package com.eascs.spider.ant.common.proj;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 各平台映射关系
 * @author hzp
 *
 */
public enum Platform {

	IFENG_NEWS("凤凰资讯", "ifeng_news", "news.ifeng*?"), 
	SINA_NEWS("新浪新闻", "sina_news", "sina*?"), 
	SINA_WEIBO("新浪微博", "sina_weibo", "weibo*?"), 
	NC_PRICE("农商价格行情", "nc_price", "http://nc.mofcom.gov.cn/channel/jghq*?"), 
	NC_INFO("农商农业资讯", "nc_info", "(http://nc.mofcom.gov.cn/channel/information*?)|(http://nc.mofcom.gov.cn/article/.*?.html)"), 
	NC_SUPPLY("农商供应信息", "nc_supply", "(http://nc.mofcom.gov.cn/channel/gxdj/gyxx*?)|(http://nc.mofcom.gov.cn/supply.*?)"), 
	ZOL_PHONE("中关村手机报价", "zol_phone", "http://detail.zol.com.cn.*?"), 
	CAR_AUTOHOME("汽车之家汽车报价及详情", "car_autohome", "https://dealer.autohome.com.cn.*?"),
	CNHNB_PRICE("惠农网市场行情", "cnhnb_price", "http://news.cnhnb.com/hangqing.*?"), 
	CNHNB_NEWS("惠农网资讯", "cnhnb_news", "http://news.cnhnb.com/zixun.*?"),
	CNHNB_PURCHASE("惠农网采购大厅", "cnhnb_purchase", "(http://www.cnhnb.com/purchase.*?)|(http://www.cnhnb.com/caigou/.*?)"),
	CNHNB_SUPPLY("惠农网采购大厅", "cnhnb_supply", "(http://www.cnhnb.com/supply)|(http://www.cnhnb.com/p/.*?)|(http://www.cnhnb.com/gongying/.*?)");

	private String name;//中文名字
	
	private String platform;//平台名称
	
	private String regex;
	
	private Platform(String name , String platform ,String regex){
		this.platform = platform;
		this.regex = regex;
		this.name = name;
	}
	
	public String getRegex() {
		return regex;
	}

	public void setRegex(String regex) {
		this.regex = regex;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPlatform() {
		return platform;
	}

	public void setPlatform(String platform) {
		this.platform = platform;
	}

	/**
	 * 根据url获取所属平台
	 * @param url
	 * @return
	 */
	public static Platform getPlatform(String url){
		Platform[] platForms = Platform.values();
		for(Platform p : platForms){
			String regex = p.getRegex();
			Pattern pattern = Pattern.compile(regex);
			Matcher matcher = pattern.matcher(url);
			if(matcher.find())
				return p;
		}
		return null;
	}
	
}
